from django.utils.decorators import method_decorator

from gis.common.django_ext.decorators import validate_parameters
from gis.common.django_ext.views import BaseView, PaginationResponse
from gis.admin.decorators import require_login, check_permission
from itpay.core.agency import blacklist_service
from . import blacklist_form
from .helper import wrapper_name


class BlackListView(BaseView):
    @method_decorator(require_login)
    @method_decorator(check_permission('blacklist_get'))
    @method_decorator(validate_parameters(blacklist_form.GetBlackListSchema))
    def get(self, request, cleaned_data):
        total, blacklist = blacklist_service.list_blacklist(**cleaned_data)
        return PaginationResponse(total, [wrapper_name(e) for e in blacklist])

